package sctu.edu.java.year2016.team06.chenqiang.day20160606.chapter11_3;

/**
 * Created by XQ on 2016/6/6.
 */

import java.util.Scanner;

public class Computer {
    public static void gcd(int x, int y) throws MyException {
        if (x < 0 || y < 0) {
            throw new MyException(x, y);
        }
        int t;
        if (x < y) {//x存放较大的数，y存放较小的数。
            t = x;
            x = y;
            y = t;
        }
        while (x % y != 0) {
            t = y;
            y = x % y;
            x = t;
        }
        System.out.println("两个数的最大公约数是：" + y);
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入任意两个数据：");
        int x = scan.nextInt();
        int y = scan.nextInt();
        Computer computer = new Computer();
        try {
            computer.gcd(x, y);
        } catch (MyException e) {
            System.out.println(e);
        }
    }
}
